/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package server;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import helper.ThreadID;

/**
 *
 * @author user
 */
public class Server {
    private static int port=1234, maxConnections=2;
  // Listen for incoming connections and handle them
    public ServerSocket listener;
    public InetAddress IP;
    public Socket server;
    public ThreadGroup threadGroup;
    private ThreadID tid;

    public Server(int port){
        //this.IP = "localhost";
        try {
            listener = new ServerSocket(port);
        } catch (IOException ex) {
            Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
        }
        this.port = port;
    }
  public static void main(String[] args) {
    int i=0;

    try{
      Server s = new Server(1234);
      //s.threadGroup = new ThreadGroup(Server.class.getName());

      while(true){
        
        ServerTask connection;
        System.out.println("Listening on port "+ s.port);
        s.server = s.listener.accept();
        ServerTask conn_c= new ServerTask(s.server, new ThreadID());
        Thread t = new Thread(conn_c);
        
        t.start();
      }
    } catch (IOException ioe) {
      System.out.println("IOException on socket listen: " + ioe);
      ioe.printStackTrace();
    
        }
    }
}

